package client;

import entity.rangerAudit;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrDocumentList;
import org.apache.solr.common.util.NamedList;

import java.io.IOException;
import java.util.*;


/**
 * Created by sqy on 2018/11/21.
 */
public class solrjOperation {
    static final String solr_url = "http://10.0.0.45:8983/solr/ranger_audits";

    public static void main(String[] args){
        SolrClient client = new HttpSolrClient.Builder(solr_url).build();
        SolrQuery query = new SolrQuery("*:*");
        query.addSort("evtTime",SolrQuery.ORDER.asc);
        QueryResponse response;

        try {
            response = client.query(query);
            SolrDocumentList docList = response.getResults();
            SolrDocument doc;
            List<rangerAudit> rangerAuditList;
            for (int i = 0; i < docList.size(); i++) {
                doc = docList.get(i);
            }
            client.commit();
            client.close();
        } catch (SolrServerException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    /*public rangerAudit convert(SolrDocument doc){
        rangerAudit audit = new rangerAudit();
        audit.setId((String)doc.getFieldValue("id"));
        audit.setAccess((String)doc.getFieldValue("access"));

    }*/

    public static void timer(){
        Timer timer = new Timer();
        timer.schedule(new TimerTask() {

            @Override
            public void run() {
                System.out.println("hello world!");
            }
        },1000,1000);
    }

}
